package com.gaoxin.api.contronller.educontroller;

import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.gaoxin.api.entity.eduentity.Clazz;
import com.gaoxin.api.entity.eduentity.Dept;
import com.gaoxin.api.service.eduservice.QueryAllClassService;
import com.gaoxin.common.utils.R;
import com.google.common.collect.Maps;

import io.swagger.annotations.Api;

/**
 * 查询所有班级-控制层
 * @author a123456
 *
 */
@RestController
@RequestMapping("/app/teaching")
@Api(tags = "查询所有班级")
public class QueryAllClassController {
	
	Logger log = Logger.getLogger("查询所有班级~~~~~~~~~~~log~~~~~~~~");
	@Autowired
	private QueryAllClassService queryAllClassService;

	
	
	@RequestMapping(value = "/queryClass", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	public String queryAllDept(@RequestBody Clazz clazz) {
		String jsonData = null;
		try {
			List<Clazz> list = queryAllClassService.queryAllClass(clazz);
			Map<String, Object> map = Maps.newHashMap();
			if(list.size()!=0&&list!=null){
				map.put("code", "0");
				map.put("results",list);
				jsonData = JSON.toJSONString(map);
			}else{
				map.put("code", "100206");
				map.put("errmsg", "无班级信息！");
				jsonData = JSON.toJSONString(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonData;
	}
	/**
	 * 查询所有的二级院系
	 * @param paramMap
	 * @return
	 */
	@RequestMapping(value = "/queryDept", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	public String queryDept() {
		String jsonData = null;
		try {
			List<Clazz> list = queryAllClassService.queryDept();
			Map<String, Object> map = Maps.newHashMap();
			if(list.size()!=0&&list!=null){
				map.put("code", "0");
				map.put("results",list);
				jsonData = JSON.toJSONString(map);
			}else{
				map.put("code", "100202");
				map.put("errmsg", "无院系信息！");
				jsonData = JSON.toJSONString(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonData;
	}
	/**
	 * 根据院系查询所属专业信息
	 * @return
	 */
	@RequestMapping(value = "/selectMajor", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	public String queryMajor(@RequestBody Clazz clazz) {
		String jsonData = null;
		try {
			List<Clazz> dept = queryAllClassService.queryMajor(clazz);
			Map<String, Object> map = Maps.newHashMap();
			if(dept!=null){
				map.put("code", "0");
				map.put("results",dept);
				jsonData = JSON.toJSONString(map);
			}else{
				map.put("code", "100203");
				map.put("errmsg", "无该院系对应的专业信息！");
				jsonData = JSON.toJSONString(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonData;
	}
}
